package org.fuckerfucker.todoapp_kotlin.data.repository

import androidx.lifecycle.LiveData
import org.fuckerfucker.todoapp_kotlin.data.TodoDao
import org.fuckerfucker.todoapp_kotlin.data.model.Todo

// repository should call dao methods
class TodoRepo(private val todoDao: TodoDao) {
    val getAllData: LiveData<List<Todo>> = todoDao.getAllData()

    suspend fun insertOne(todo: Todo) = todoDao.insertData(todo)

    suspend fun updateOne(todo: Todo) = todoDao.updateData(todo)

    suspend fun deleteItem(todo: Todo) = todoDao.deleteItem(todo)

    suspend fun deleteAll() = todoDao.deleteAll()

    fun searchDatabase(searchQuery: String): LiveData<List<Todo>> = todoDao.searchTable(searchQuery)
    // 排序
    val sortByHighPriority: LiveData<List<Todo>> = todoDao.sortByHighPriority()
    val sortByLowPriority: LiveData<List<Todo>> = todoDao.sortByLowPriority()
}